package generalpattern.diagram.providers;

import generalpattern.diagram.edit.parts.Component2EditPart;
import generalpattern.diagram.edit.parts.Component3EditPart;
import generalpattern.diagram.edit.parts.ComponentEditPart;
import generalpattern.diagram.edit.parts.ComponentPortAttachedRoleEditPart;
import generalpattern.diagram.edit.parts.ComponentPortDelegatedPortsEditPart;
import generalpattern.diagram.edit.parts.ComponentPortEditPart;
import generalpattern.diagram.edit.parts.Connector2EditPart;
import generalpattern.diagram.edit.parts.Connector3EditPart;
import generalpattern.diagram.edit.parts.ConnectorEditPart;
import generalpattern.diagram.edit.parts.ConnectorRoleDelegatedRolesEditPart;
import generalpattern.diagram.edit.parts.ConnectorRoleEditPart;
import generalpattern.diagram.edit.parts.ConstraintEditPart;
import generalpattern.diagram.edit.parts.ElementMultiplicityEditPart;
import generalpattern.diagram.edit.parts.ElementRolesEditPart;
import generalpattern.diagram.edit.parts.MergingOperatorSourceEditPart;
import generalpattern.diagram.edit.parts.MergingOperatorTargetEditPart;
import generalpattern.diagram.edit.parts.Multiplicity2EditPart;
import generalpattern.diagram.edit.parts.MultiplicityEditPart;
import generalpattern.diagram.edit.parts.Overlapping2EditPart;
import generalpattern.diagram.edit.parts.OverlappingEditPart;
import generalpattern.diagram.edit.parts.Pattern2EditPart;
import generalpattern.diagram.edit.parts.Pattern3EditPart;
import generalpattern.diagram.edit.parts.Pattern4EditPart;
import generalpattern.diagram.edit.parts.PatternEditPart;
import generalpattern.diagram.edit.parts.Role2EditPart;
import generalpattern.diagram.edit.parts.RoleEditPart;
import generalpattern.diagram.edit.parts.Stringing2EditPart;
import generalpattern.diagram.edit.parts.StringingEditPart;
import generalpattern.diagram.part.GeneralPatternMetamodelDiagramEditorPlugin;

import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Set;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.ENamedElement;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Image;

/**
 * @generated
 */
public class GeneralPatternMetamodelElementTypes {

	/**
	 * @generated
	 */
	private GeneralPatternMetamodelElementTypes() {
	}

	/**
	 * @generated
	 */
	private static Map/*[org.eclipse.gmf.runtime.emf.type.core.IElementType, org.eclipse.emf.ecore.ENamedElement]*/elements;

	/**
	 * @generated
	 */
	private static ImageRegistry imageRegistry;

	/**
	 * @generated
	 */
	private static Set/*[org.eclipse.gmf.runtime.emf.type.core.IElementType]*/KNOWN_ELEMENT_TYPES;

	/**
	 * @generated
	 */
	public static final IElementType Pattern_1000 = getElementType("org.admanager.generalpattern.plugin.diagram.Pattern_1000"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Pattern_2022 = getElementType("org.admanager.generalpattern.plugin.diagram.Pattern_2022"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Component_2023 = getElementType("org.admanager.generalpattern.plugin.diagram.Component_2023"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Connector_2024 = getElementType("org.admanager.generalpattern.plugin.diagram.Connector_2024"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Role_2025 = getElementType("org.admanager.generalpattern.plugin.diagram.Role_2025"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Multiplicity_2026 = getElementType("org.admanager.generalpattern.plugin.diagram.Multiplicity_2026"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Overlapping_2027 = getElementType("org.admanager.generalpattern.plugin.diagram.Overlapping_2027"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Stringing_2028 = getElementType("org.admanager.generalpattern.plugin.diagram.Stringing_2028"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Role_3023 = getElementType("org.admanager.generalpattern.plugin.diagram.Role_3023"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Constraint_3024 = getElementType("org.admanager.generalpattern.plugin.diagram.Constraint_3024"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Component_3025 = getElementType("org.admanager.generalpattern.plugin.diagram.Component_3025"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType ComponentPort_3026 = getElementType("org.admanager.generalpattern.plugin.diagram.ComponentPort_3026"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Component_3027 = getElementType("org.admanager.generalpattern.plugin.diagram.Component_3027"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Connector_3028 = getElementType("org.admanager.generalpattern.plugin.diagram.Connector_3028"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType ConnectorRole_3029 = getElementType("org.admanager.generalpattern.plugin.diagram.ConnectorRole_3029"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Pattern_3030 = getElementType("org.admanager.generalpattern.plugin.diagram.Pattern_3030"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Connector_3031 = getElementType("org.admanager.generalpattern.plugin.diagram.Connector_3031"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Pattern_3032 = getElementType("org.admanager.generalpattern.plugin.diagram.Pattern_3032"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Multiplicity_3033 = getElementType("org.admanager.generalpattern.plugin.diagram.Multiplicity_3033"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Overlapping_3034 = getElementType("org.admanager.generalpattern.plugin.diagram.Overlapping_3034"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Stringing_3035 = getElementType("org.admanager.generalpattern.plugin.diagram.Stringing_3035"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType ElementRoles_4016 = getElementType("org.admanager.generalpattern.plugin.diagram.ElementRoles_4016"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType ElementMultiplicity_4013 = getElementType("org.admanager.generalpattern.plugin.diagram.ElementMultiplicity_4013"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType MergingOperatorSource_4017 = getElementType("org.admanager.generalpattern.plugin.diagram.MergingOperatorSource_4017"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType MergingOperatorTarget_4018 = getElementType("org.admanager.generalpattern.plugin.diagram.MergingOperatorTarget_4018"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType ConnectorRoleDelegatedRoles_4019 = getElementType("org.admanager.generalpattern.plugin.diagram.ConnectorRoleDelegatedRoles_4019"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType ComponentPortDelegatedPorts_4020 = getElementType("org.admanager.generalpattern.plugin.diagram.ComponentPortDelegatedPorts_4020"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType ComponentPortAttachedRole_4005 = getElementType("org.admanager.generalpattern.plugin.diagram.ComponentPortAttachedRole_4005"); //$NON-NLS-1$

	/**
	 * @generated
	 */
	private static ImageRegistry getImageRegistry() {
		if (imageRegistry == null) {
			imageRegistry = new ImageRegistry();
		}
		return imageRegistry;
	}

	/**
	 * @generated
	 */
	private static String getImageRegistryKey(ENamedElement element) {
		return element.getName();
	}

	/**
	 * @generated
	 */
	private static ImageDescriptor getProvidedImageDescriptor(
			ENamedElement element) {
		if (element instanceof EStructuralFeature) {
			EStructuralFeature feature = ((EStructuralFeature) element);
			EClass eContainingClass = feature.getEContainingClass();
			EClassifier eType = feature.getEType();
			if (eContainingClass != null && !eContainingClass.isAbstract()) {
				element = eContainingClass;
			} else if (eType instanceof EClass
					&& !((EClass) eType).isAbstract()) {
				element = eType;
			}
		}
		if (element instanceof EClass) {
			EClass eClass = (EClass) element;
			if (!eClass.isAbstract()) {
				return GeneralPatternMetamodelDiagramEditorPlugin.getInstance()
						.getItemImageDescriptor(
								eClass.getEPackage().getEFactoryInstance()
										.create(eClass));
			}
		}
		// TODO : support structural features
		return null;
	}

	/**
	 * @generated
	 */
	public static ImageDescriptor getImageDescriptor(ENamedElement element) {
		String key = getImageRegistryKey(element);
		ImageDescriptor imageDescriptor = getImageRegistry().getDescriptor(key);
		if (imageDescriptor == null) {
			imageDescriptor = getProvidedImageDescriptor(element);
			if (imageDescriptor == null) {
				imageDescriptor = ImageDescriptor.getMissingImageDescriptor();
			}
			getImageRegistry().put(key, imageDescriptor);
		}
		return imageDescriptor;
	}

	/**
	 * @generated
	 */
	public static Image getImage(ENamedElement element) {
		String key = getImageRegistryKey(element);
		Image image = getImageRegistry().get(key);
		if (image == null) {
			ImageDescriptor imageDescriptor = getProvidedImageDescriptor(element);
			if (imageDescriptor == null) {
				imageDescriptor = ImageDescriptor.getMissingImageDescriptor();
			}
			getImageRegistry().put(key, imageDescriptor);
			image = getImageRegistry().get(key);
		}
		return image;
	}

	/**
	 * @generated
	 */
	public static ImageDescriptor getImageDescriptor(IAdaptable hint) {
		ENamedElement element = getElement(hint);
		if (element == null) {
			return null;
		}
		return getImageDescriptor(element);
	}

	/**
	 * @generated
	 */
	public static Image getImage(IAdaptable hint) {
		ENamedElement element = getElement(hint);
		if (element == null) {
			return null;
		}
		return getImage(element);
	}

	/**
	 * Returns 'type' of the ecore object associated with the hint.
	 * 
	 * @generated
	 */
	public static ENamedElement getElement(IAdaptable hint) {
		Object type = hint.getAdapter(IElementType.class);
		if (elements == null) {
			elements = new IdentityHashMap/*[org.eclipse.gmf.runtime.emf.type.core.IElementType, org.eclipse.emf.ecore.ENamedElement]*/();

			elements.put(
					Pattern_1000,
					org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
							.getPattern());

			elements.put(
					Pattern_2022,
					org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
							.getPattern());

			elements.put(
					Component_2023,
					org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
							.getComponent());

			elements.put(
					Connector_2024,
					org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
							.getConnector());

			elements.put(
					Role_2025,
					org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
							.getRole());

			elements.put(
					Multiplicity_2026,
					org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
							.getMultiplicity());

			elements.put(
					Overlapping_2027,
					org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
							.getOverlapping());

			elements.put(
					Stringing_2028,
					org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
							.getStringing());

			elements.put(
					Role_3023,
					org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
							.getRole());

			elements.put(
					Constraint_3024,
					org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
							.getConstraint());

			elements.put(
					Component_3025,
					org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
							.getComponent());

			elements.put(
					ComponentPort_3026,
					org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
							.getComponentPort());

			elements.put(
					Component_3027,
					org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
							.getComponent());

			elements.put(
					Connector_3028,
					org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
							.getConnector());

			elements.put(
					ConnectorRole_3029,
					org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
							.getConnectorRole());

			elements.put(
					Pattern_3030,
					org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
							.getPattern());

			elements.put(
					Connector_3031,
					org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
							.getConnector());

			elements.put(
					Pattern_3032,
					org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
							.getPattern());

			elements.put(
					Multiplicity_3033,
					org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
							.getMultiplicity());

			elements.put(
					Overlapping_3034,
					org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
							.getOverlapping());

			elements.put(
					Stringing_3035,
					org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
							.getStringing());

			elements.put(
					ElementRoles_4016,
					org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
							.getElement_Roles());

			elements.put(
					ElementMultiplicity_4013,
					org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
							.getElement_Multiplicity());

			elements.put(
					MergingOperatorSource_4017,
					org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
							.getMergingOperator_Source());

			elements.put(
					MergingOperatorTarget_4018,
					org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
							.getMergingOperator_Target());

			elements.put(
					ConnectorRoleDelegatedRoles_4019,
					org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
							.getConnectorRole_DelegatedRoles());

			elements.put(
					ComponentPortDelegatedPorts_4020,
					org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
							.getComponentPort_DelegatedPorts());

			elements.put(
					ComponentPortAttachedRole_4005,
					org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage.eINSTANCE
							.getComponentPort_AttachedRole());
		}
		return (ENamedElement) elements.get(type);
	}

	/**
	 * @generated
	 */
	private static IElementType getElementType(String id) {
		return ElementTypeRegistry.getInstance().getType(id);
	}

	/**
	 * @generated
	 */
	public static boolean isKnownElementType(IElementType elementType) {
		if (KNOWN_ELEMENT_TYPES == null) {
			KNOWN_ELEMENT_TYPES = new HashSet/*[org.eclipse.gmf.runtime.emf.type.core.IElementType]*/();
			KNOWN_ELEMENT_TYPES.add(Pattern_1000);
			KNOWN_ELEMENT_TYPES.add(Pattern_2022);
			KNOWN_ELEMENT_TYPES.add(Component_2023);
			KNOWN_ELEMENT_TYPES.add(Connector_2024);
			KNOWN_ELEMENT_TYPES.add(Role_2025);
			KNOWN_ELEMENT_TYPES.add(Multiplicity_2026);
			KNOWN_ELEMENT_TYPES.add(Overlapping_2027);
			KNOWN_ELEMENT_TYPES.add(Stringing_2028);
			KNOWN_ELEMENT_TYPES.add(Role_3023);
			KNOWN_ELEMENT_TYPES.add(Constraint_3024);
			KNOWN_ELEMENT_TYPES.add(Component_3025);
			KNOWN_ELEMENT_TYPES.add(ComponentPort_3026);
			KNOWN_ELEMENT_TYPES.add(Component_3027);
			KNOWN_ELEMENT_TYPES.add(Connector_3028);
			KNOWN_ELEMENT_TYPES.add(ConnectorRole_3029);
			KNOWN_ELEMENT_TYPES.add(Pattern_3030);
			KNOWN_ELEMENT_TYPES.add(Connector_3031);
			KNOWN_ELEMENT_TYPES.add(Pattern_3032);
			KNOWN_ELEMENT_TYPES.add(Multiplicity_3033);
			KNOWN_ELEMENT_TYPES.add(Overlapping_3034);
			KNOWN_ELEMENT_TYPES.add(Stringing_3035);
			KNOWN_ELEMENT_TYPES.add(ElementRoles_4016);
			KNOWN_ELEMENT_TYPES.add(ElementMultiplicity_4013);
			KNOWN_ELEMENT_TYPES.add(MergingOperatorSource_4017);
			KNOWN_ELEMENT_TYPES.add(MergingOperatorTarget_4018);
			KNOWN_ELEMENT_TYPES.add(ConnectorRoleDelegatedRoles_4019);
			KNOWN_ELEMENT_TYPES.add(ComponentPortDelegatedPorts_4020);
			KNOWN_ELEMENT_TYPES.add(ComponentPortAttachedRole_4005);
		}
		return KNOWN_ELEMENT_TYPES.contains(elementType);
	}

	/**
	 * @generated
	 */
	public static IElementType getElementType(int visualID) {
		switch (visualID) {
		case PatternEditPart.VISUAL_ID:
			return Pattern_1000;
		case Pattern2EditPart.VISUAL_ID:
			return Pattern_2022;
		case ComponentEditPart.VISUAL_ID:
			return Component_2023;
		case ConnectorEditPart.VISUAL_ID:
			return Connector_2024;
		case Role2EditPart.VISUAL_ID:
			return Role_2025;
		case Multiplicity2EditPart.VISUAL_ID:
			return Multiplicity_2026;
		case Overlapping2EditPart.VISUAL_ID:
			return Overlapping_2027;
		case Stringing2EditPart.VISUAL_ID:
			return Stringing_2028;
		case RoleEditPart.VISUAL_ID:
			return Role_3023;
		case ConstraintEditPart.VISUAL_ID:
			return Constraint_3024;
		case Component2EditPart.VISUAL_ID:
			return Component_3025;
		case ComponentPortEditPart.VISUAL_ID:
			return ComponentPort_3026;
		case Component3EditPart.VISUAL_ID:
			return Component_3027;
		case Connector2EditPart.VISUAL_ID:
			return Connector_3028;
		case ConnectorRoleEditPart.VISUAL_ID:
			return ConnectorRole_3029;
		case Pattern3EditPart.VISUAL_ID:
			return Pattern_3030;
		case Connector3EditPart.VISUAL_ID:
			return Connector_3031;
		case Pattern4EditPart.VISUAL_ID:
			return Pattern_3032;
		case MultiplicityEditPart.VISUAL_ID:
			return Multiplicity_3033;
		case OverlappingEditPart.VISUAL_ID:
			return Overlapping_3034;
		case StringingEditPart.VISUAL_ID:
			return Stringing_3035;
		case ElementRolesEditPart.VISUAL_ID:
			return ElementRoles_4016;
		case ElementMultiplicityEditPart.VISUAL_ID:
			return ElementMultiplicity_4013;
		case MergingOperatorSourceEditPart.VISUAL_ID:
			return MergingOperatorSource_4017;
		case MergingOperatorTargetEditPart.VISUAL_ID:
			return MergingOperatorTarget_4018;
		case ConnectorRoleDelegatedRolesEditPart.VISUAL_ID:
			return ConnectorRoleDelegatedRoles_4019;
		case ComponentPortDelegatedPortsEditPart.VISUAL_ID:
			return ComponentPortDelegatedPorts_4020;
		case ComponentPortAttachedRoleEditPart.VISUAL_ID:
			return ComponentPortAttachedRole_4005;
		}
		return null;
	}

}
